<?php
namespace App\Controller\Admin;

use App\Query\ShopQuery;
use App\Query\UserPayQuery;
use App\Repository\ShopRepository;

class ShopController extends Controller
{
    // 列表
    public function index()
    {
        return ShopQuery::query(
            ShopQuery::model(),
            $this->inputs('user_id', 'shop_id', 'status')
        )->paginate(15)->toArray();
    }
    
    // 审核
    public function status($id)
    {
        $model = ShopRepository::find($id);

        if($model && $model->setStatusOk())
        {
            $this->message('ok');
        }
        
        $this->error('error');
    }
    
    // 当前业绩
    public function money($id)
    {
        if($model = ShopRepository::find($id))
        {
            $money = UserPayQuery::totalMoney($model->getCheckTime(), $model->model()->userPay());
        
            return compact('money');
        }
        
        $this->error('error');
    }
    
    // 修改信息
    public function info($id)
    {
        if($model = ShopRepository::find($id))
        {
            $model->save($this->inputs('name'));
        
            $this->message('ok');
        }
        
        $this->error('error');
    }
}